package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BizDicProblem;
import com.ruoyi.system.service.IBizDicProblemService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 问题字典Controller
 * 
 * @author gaofeng
 * @date 2025-07-08
 */
@Controller
@RequestMapping("/system/problem")
public class BizDicProblemController extends BaseController
{
    private String prefix = "system/problem";

    @Autowired
    private IBizDicProblemService bizDicProblemService;

    @RequiresPermissions("system:problem:view")
    @GetMapping()
    public String problem()
    {
        return prefix + "/problem";
    }

    /**
     * 查询问题字典列表
     */
    @RequiresPermissions("system:problem:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizDicProblem bizDicProblem)
    {
        startPage();
        List<BizDicProblem> list = bizDicProblemService.selectBizDicProblemList(bizDicProblem);
        return getDataTable(list);
    }

    /**
     * 导出问题字典列表
     */
    @RequiresPermissions("system:problem:export")
    @Log(title = "问题字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizDicProblem bizDicProblem)
    {
        List<BizDicProblem> list = bizDicProblemService.selectBizDicProblemList(bizDicProblem);
        ExcelUtil<BizDicProblem> util = new ExcelUtil<BizDicProblem>(BizDicProblem.class);
        return util.exportExcel(list, "问题字典数据");
    }

    /**
     * 新增问题字典
     */
    @RequiresPermissions("system:problem:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存问题字典
     */
    @RequiresPermissions("system:problem:add")
    @Log(title = "问题字典", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizDicProblem bizDicProblem)
    {
        return toAjax(bizDicProblemService.insertBizDicProblem(bizDicProblem));
    }

    /**
     * 修改问题字典
     */
    @RequiresPermissions("system:problem:edit")
    @GetMapping("/edit/{sn}")
    public String edit(@PathVariable("sn") Long sn, ModelMap mmap)
    {
        BizDicProblem bizDicProblem = bizDicProblemService.selectBizDicProblemBySn(sn);
        mmap.put("bizDicProblem", bizDicProblem);
        return prefix + "/edit";
    }

    /**
     * 修改保存问题字典
     */
    @RequiresPermissions("system:problem:edit")
    @Log(title = "问题字典", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizDicProblem bizDicProblem)
    {
        return toAjax(bizDicProblemService.updateBizDicProblem(bizDicProblem));
    }

    /**
     * 删除问题字典
     */
    @RequiresPermissions("system:problem:remove")
    @Log(title = "问题字典", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bizDicProblemService.deleteBizDicProblemBySns(ids));
    }
}
